We use a variational wave function to calculate the energy of the interaction between external charges in the compact Abelian gauge theory in 2+1 dimensions with mixed action. Our variational wave functions preserve the compact gauge invariance of the theory both in the vacuum and in the charged sectors. We find that a good estimate of the interaction energy is obtained only when we allow more variational parameters in the charged sector than in the vacuum sector. These extra parameters are the profile of an induced electric field. We find that the theory has a two-phase structure: When the charge-2 coupling is large and negative there is no mass gap in the theory and no confinement, while otherwise a mass gap is generated dynamically and the theory confines charges. The pure Wilson theory is in the confining phase.